<?php
	require_once ('scripts.php');
	require_once ('model/dao/vo/VehicleVO.php');
	require_once ('model/dao/vo/SubmissionVO.php');

	$action = $_REQUEST['action'];
	
	
	if($action == 'create')
	{
		$object=new VehicleVO();
		$object->year = $_POST['year'];
		$object->make=$_POST['make'];
		$object->model=$_POST['model'];
		//$object->vin=$_POST['vin'];
		$object->mileage=$_POST['mileage'];
		$object->engine=$_POST['engine'];
		$object->transmission=$_POST['transmission'];
		$object->drivetrain_type=$_POST['drivetrain_type'];
		//$object->title_note=$_POST['title_note'];
		$object->wrong=$_POST['wrong'];
		$object->great=$_POST['great'];
		$object->i_want_to=$_POST['i_want_to'];
		$object->first_name=$_POST['first_name'];
		$object->phone=$_POST['phone'];
		$object->email=$_POST['email'];
		//$object->contact_me=$_POST['contact_me'];
		//$object->paper_work=$_POST['paper_work'];
		$object->street_address=$_POST['street_address'];
		$object->city=$_POST['city'];
		$object->state=$_POST['state'];
		$object->zip=$_POST['zip'];
		$object->located_at=$_POST['located_at'];
		//$object->delivery=$_POST['delivery'];
		$object->asking_price=$_POST['asking_price'];
		$object->bid_price=0;
		$object->is_watch=0;
		$object->is_read=0;
		$object->accepted_price=0;
		$object->removal_date=$_POST['removal_date'];
		$object->status='New Submission';
		$object->current_action='New Submission';
		$object->is_partner=0;
	     
		createNewVehicle($object);
	}
	
	function createNewVehicle($vehicle) 
	{   
		date_default_timezone_set('America/Los_Angeles');
		$myDate = date('Y-m-d H:i:s');
		$o_date = date('Y-m-d');
		$adminUser = NULL;
		$type = 'mSellerSubmit';
  		$email = $vehicle->email;
  		$vid = $vehicle->vehicle_id;		
  		$query_insert = "INSERT INTO vehicle ( `vehicle_id` , `year` , `make` , `model` , `vin` , `mileage` , `engine` , `transmission` , `drivetrain_type` , `title_note` , `title_name` , `ad_source` , `color` , `wrong` , `great` , `i_want_to` , `bid_price` , `asking_price`, `accepted_price` , `removal_date` , `first_name` , `email` , `phone` , `cell_phone` , `contact_me` , `located_at` , `paper_work` , `street_address` , `city` , `state` , `zip` , `v_street_address` , `v_city` , `v_state` , `v_zip` , `contact_name` , `bussiness_name` , `contact_phone` , `delivery` , `delivery_note` , `delivery_option` , `private_note` , `contact_note` , `is_watch` , `is_read` , `status` , `current_action` ,`locked_by`,`locked_id`,`assist_by`,`locked_date`, `update_date` , `date`, `created_by`, `is_partner` ) VALUES (NULL,'".$vehicle->year. "','" .addslashes($vehicle->make). "','" .addslashes($vehicle->model). "','" .addslashes($vehicle->vin). "','" .addslashes($vehicle->mileage). "','" .addslashes($vehicle->engine). "','" .addslashes($vehicle->transmission). "','" .addslashes($vehicle->drivetrain_type). "','" .addslashes($vehicle->title_note). "','" .addslashes($vehicle->title_name). "','" .addslashes($vehicle->ad_source). "','" .addslashes($vehicle->color). "','" .addslashes($vehicle->wrong). "','" .addslashes($vehicle->great). "','" .addslashes($vehicle->i_want_to). "',".$vehicle->bid_price.",".$vehicle->asking_price.",".$vehicle->accepted_price.",'" .$vehicle->removal_date. "','" .addslashes($vehicle->first_name). "','" .addslashes($vehicle->email). "','" .$vehicle->phone. "','" .$vehicle->cell_phone. "','" .addslashes($vehicle->contact_me). "','" .addslashes($vehicle->located_at). "','" .addslashes($vehicle->paper_work). "','" .addslashes($vehicle->street_address). "','" .addslashes($vehicle->city). "','" .addslashes($vehicle->state). "','" .addslashes($vehicle->zip). "','" .addslashes($vehicle->v_street_address). "','" .addslashes($vehicle->v_city). "','" .addslashes($vehicle->v_state). "','" .addslashes($vehicle->v_zip). "','" .addslashes($vehicle->contact_name). "','" .addslashes($vehicle->bussiness_name). "','" .$vehicle->contact_phone. "','" .addslashes($vehicle->delivery). "','" .addslashes($vehicle->delivery_note). "','" .addslashes($vehicle->delivery_option). "','" .addslashes($vehicle->private_note). "','" .addslashes($vehicle->contact_note). "'," .$vehicle->is_watch. ",".$vehicle->is_read.",'" .addslashes($vehicle->status). "','" .addslashes($vehicle->current_action). "','" .addslashes($vehicle->locked_by). "',0,'" .addslashes($adminUser). "','" .$myDate."','" .$myDate."','" .$myDate."','".addslashes($vehicle->first_name)."',".$vehicle->is_partner.")";
		$result_insert = mysql_query($query_insert) or die("Query ERROR9".$query_insert);
		$lastInsertedID = mysql_insert_id();	
		$submissionVO = new SubmissionVO();
		$submissionVO->via_m_seller = 1;
		$submissionVO->sub_platform = 'Mobile OS';
		$submissionVO->sub_device = 'Mobile';
		$submissionVO->sub_ip = '';
		$submissionVO->latitude = '';
		$submissionVO->longtitude = '';
		$submissionVO->via_w_seller = 0;
		$submissionVO->via_w_buyer = 0;
		$submissionVO->via_m_buyer = 0;

	

		$submission_insert = "INSERT INTO submission_tracker (`vehicle_id`,`sub_ip`,`sub_platform`,`sub_device`,`gps_latitude`,`gps_longtitude`,`via_web_seller`,
		`via_web_buyer`,`via_mobile_seller`,`via_mobile_buyer`,`date`) VALUES (".$lastInsertedID.",'".$submissionVO->sub_ip."','".$submissionVO->sub_platform."','".$submissionVO->sub_device."','".$submissionVO->latitude."','".$submissionVO->longtitude."',".$submissionVO->via_w_seller.",".$submissionVO->via_w_buyer.",".$submissionVO->via_m_seller.",".$submissionVO->via_m_buyer.",'".$o_date."')";
		$submission_result = mysql_query($submission_insert) or die("Query ERROR111".$submission_insert);	
		$vehicle->vehicle_id = $lastInsertedID;
		VehicleDAOImpl::getInstance()->emailNotificationSender($vehicle, $type, $adminUser, $lastInsertedID);
		
		echo $lastInsertedID;
    }
	?>